package tcards.android;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class MultiField extends RelativeLayout {
	private void init(AttributeSet attrs) {
		TypedArray tArray = getContext().obtainStyledAttributes(attrs, R.styleable.Field);
		
		String text = tArray.getString(R.styleable.Field_label);
        if (text != null) { 
        	getLabel().setText(text + ":");
        }
		
        getInput().getLayoutParams().width = tArray.getInt(R.styleable.Field_inputSize, 350);
        
		tArray.recycle();
	}	
	
	public MultiField(Context context) {
		this(context, null, 0);
	}

	public MultiField(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public MultiField(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		LayoutInflater li = LayoutInflater.from(context);
		addView(li.inflate(R.layout.multi_field, this, false));
		if (attrs != null) {
			init(attrs);
		}
	}

	public TextView getLabel() {
		return (TextView) findViewById(R.id.multiLabel);
	}
	
	public EditText getInput() {
		return (EditText) findViewById(R.id.multiInput);
	}

	public String getTextValue() {
		return getInput().getText().toString();
	}
	
	public void setTextValue(String s) {
		if(s == null)
			s = "";
		
		getInput().setText(s);
	}
}